﻿@namespace MudBlazor
@using MudBlazor.Interfaces
@inherits MudBaseButton


<div class="@Classname" onmouseleave="@(EventCallback.Factory.Create<EventArgs>(this, OnMouseOut))">
    @if (ActivatorContent != null)
    {
        <CascadingValue Value="@((IActivatable) this)" IsFixed="true">
            <div style="cursor: pointer;" @onmouseup="ToggleMenu" @onmouseover="OnMouseOver"
                 oncontextmenu="@(ActivationEvent == MouseEvent.RightClick ? "return false;" : "")">
                @ActivatorContent
            </div>
        </CascadingValue>
    }
    else if (String.IsNullOrEmpty(Icon))
    {
        <MudButton StartIcon="@StartIcon"
                   EndIcon="@EndIcon"
                   IconColor="@IconColor"
                   Color="@Color"
                   Size="@Size"
                   Variant="@Variant"
                   Disabled="@Disabled"
                   DisableRipple="@DisableRipple"
                   DisableElevation="@DisableElevation"
                   @onclick="@ToggleMenu">
            @Label
        </MudButton>
    }
    else
    {
        <MudIconButton Icon="@Icon" Color="@Color" Size="@Size" Disabled="@Disabled" DisableRipple="@DisableRipple" @onclick="@ToggleMenu" />
    }
    <CascadingValue Value="@this">
        <MudPopover Open="@_isOpen" Class="@MenuClassname" MaxHeight="@MaxHeight" Style="@PopoverStyle" Direction="@Direction" OffsetX="@OffsetX" OffsetY="@OffsetY">
            <MudList Clickable="true" Dense="@Dense">
                @ChildContent
            </MudList>
        </MudPopover>
    </CascadingValue>
</div>

<MudOverlay Visible="@(_isOpen && ActivationEvent != MouseEvent.MouseOver)" OnClick="@ToggleMenu" LockScroll="false" />

